package com.uzhie.jt808.spring;

import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * Created by TangFei on 2018/8/9.
 * 方法调用类
 */
public class MethodInvoke<T> {

    public volatile ConcurrentMap<T,ClassMethod> methodMap = new ConcurrentHashMap();

    public MethodInvoke() {
    }

    public void put(T msgID, ClassMethod classMethod) {
        methodMap.put(msgID, classMethod);
    }

    public Object invoke(T msgID, Object... params) throws InvocationTargetException, IllegalAccessException {
        ClassMethod classMethod = methodMap.get(msgID);
        Object invoke = classMethod.getMappingMethod().invoke(classMethod.getClassIns(), params);
        return invoke;
    }

}
